package com.ysu.yybk.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：lhw
 * @date ：Created in 2019/11/25 10:23
 */
@Configuration
public class RedissionConfig {
        @Autowired
        RedisProperties redisProperties;

        @Bean
        public RedissonClient redissonClient(){
            Config config = new Config();
            String redisUrl = String.format("redis://%s:%s",redisProperties.getHost()+"",redisProperties.getPort()+"");
            config.useSingleServer().setAddress(redisUrl).setPassword(redisProperties.getPassword());
            config.useSingleServer().setDatabase(0);
            return Redisson.create(config);
        }
}
